package io.gitee.cengxiaoxiao.converters;

import io.gitee.cengxiaoxiao.annotations.DictConvert;
import io.gitee.cengxiaoxiao.enums.DictType;

import java.util.HashMap;
import java.util.Map;

public class ConverterFactory {

    private static final Map<DictType, AbstractDictConverter> converters = new HashMap<>();

    static {
        converters.put(DictType.NONE, null);
        converters.put(DictType.GENDER, new GenderDictConverter());
    }

    public static AbstractDictConverter getConverter(DictType type) {
        AbstractDictConverter converter = converters.get(type);
        if (converter == null) {
            throw new IllegalArgumentException("Converter not found for type: " + type);
        }
        return converter;
    }

    public static Object convert(Object value, DictConvert dictConvert) {
        return getConverter(dictConvert.type()).convert(value, dictConvert.codeToText());
    }
}
